package com.lb.excel;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: zhangjun
 * @Date: 2024-07-10
 * @Description:
 */
public class Hutool2Test {
    public static void main(String[] args) {
        String tmpFilePath = System.currentTimeMillis() + ".xlsx";
        File destFile = null;
        try {
            destFile = FileUtil.newFile(tmpFilePath);
        } catch (Exception e) {
           e.printStackTrace();
        }
        String[] columnNameArray = ArrayUtil.toArray(CollUtil.newArrayList(
                "shopNo", "goodsNo","colorNo", "colorName", "sizeNo", "sizeName", "activityType", "productId",
                "availableInvNums", "activityApplyNums", "activityNums", "saleNums"), String.class);
        String[] tableNameArray = ArrayUtil.toArray(CollUtil.newArrayList(
                "店铺编号", "商品编号", "颜色编号", "颜色名称", "尺码编号", "尺码名称", "活动类型",
                "商品ID", "店铺可用库存", "锁定申请数量", "锁定剩余数量", "销售数量"), String.class);
        List<LockedInvDto> projects = new ArrayList<>();
        LockedInvDto dto = new LockedInvDto();
        dto.setShopNo("锁定11");
        projects.add(dto);

        for (int i = 1; i <= 3; i++) {
            ExcelWriter writer = ExcelUtil.getBigWriter("C:\\Users\\PC\\IdeaProjects\\my-test\\123.xlsx", "sheet" + i);
//            writer.setSheet(i);
            for (int j = 0; j < columnNameArray.length; j++) {
                writer.setColumnWidth(j, 20);
                writer.addHeaderAlias(columnNameArray[j], tableNameArray[j]);
            }

            writer.setOnlyAlias(true);
            // 一次性写出内容，使用默认样式，强制输出标题
            writer.write(projects, true);
            writer.close();
        }
    }
}
